<?php

/**
 * Subclass for representing a row from the 'user' table.
 *
 * 
 *
 * @package lib.model
 */ 
class User extends BaseUser
{
  public function __toString()
  {
  	return $this->getId();
  }
  
  public function setHashedPassword($password)
  {
    $this->setSalt(myTools::makeSalt($this->getId().$this->getUsername().$this->getEmail()));
    $this->setPassword($this->getHash($password));
  }
  
  public function getLastPost()
  {
  	$posts = $this->getRecent();
  	return $posts[0];
  }
  
  public function hasPassword($password)
  {
  	if ($this->getHash($password) === $this->getPassword())
  	{
  	  return true;
  	}
  	
  	return false;
  }
  
  protected function getHash($password)
  {
  	return sha1($this->getSalt().$password);
  }
  
  public function getRecent()
  {
  	$c = new Criteria();
  	$c->addDescendingOrderByColumn(PostPeer::PUBLISHED);
  	$c->setLimit(sfConfig::get('app_limit_recent'));
  	
  	return $this->getPosts($c);
  }
}
